﻿<Window x:Class="ReportingManagement.Components.DHIS.DatasetComparer"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:GenericTools.Models;assembly=GenericTools"
    xmlns:dhis="clr-namespace:ReportingManagement.Components.DHIS" 
    mc:Ignorable="d" Title="Reports and Datasets Comparison"
    Width="800" Height="440" WindowStartupLocation="CenterOwner"
    d:DesignHeight="300" d:DesignWidth="501">
    <Window.Resources>
        <ObjectDataProvider x:Key="reportsProvider" ObjectType="{x:Type local:ModelDataRetriever}" 
                            MethodName="GetReports" IsAsynchronous="True" />
        <ObjectDataProvider x:Key="datasetsProvider" ObjectType="{x:Type dhis:DHISDataBridge}"
                            MethodName="GetAllDataSets" IsAsynchronous="True" />
    </Window.Resources>

    <Grid Margin="5">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="2*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="5*" MinWidth="500" />
        </Grid.ColumnDefinitions>

        <DockPanel Background="LightBlue">
            <ListBox x:Name="lstReports" Margin="3" ItemsSource="{Binding Source={StaticResource reportsProvider}}"
                     ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectedValue="{Binding ReportId}"
                     SelectedValuePath="RepID">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock TextTrimming="CharacterEllipsis" ToolTip="{Binding Description}">
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{}{0} - {1}">
                                    <Binding Path="RepVersion" />
                                    <Binding Path="ReportName" />
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </DockPanel>
        <GridSplitter Grid.Column="1" VerticalAlignment="Stretch" Width="3" Margin="3,0,0,0" HorizontalAlignment="Center" />

        <Grid x:Name="gridDaataset" Grid.Column="2" Margin="3">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition />
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <Label>
                <TextBlock Text="{Binding SelectedItem.ReportName, ElementName=lstReports}" FontWeight="Bold"
                           TextTrimming="CharacterEllipsis" FontSize="16"/>
            </Label>
                   
            <Grid Grid.Row="1">
                <Grid.Resources>
                    <Style TargetType="{x:Type ComboBox}">
                        <Setter Property="Margin" Value="2" />
                    </Style>
                </Grid.Resources>

                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <Label Content="Report Aggregation" />
                <ComboBox x:Name="cboReportAggregation" Grid.Column="1" DisplayMemberPath="Value" SelectedValuePath="Key" 
                          SelectionChanged="cboReportAggregation_SelectionChanged" SelectedValue="{Binding AggregationLevel}" 
                          IsEnabled="{Binding IsEnabled, ElementName=btnGetReport}" />
                <Label Grid.Column="3">
                    <TextBlock>
                        Start Date <Italic FontSize="10">(yyyy, mm)</Italic>
                    </TextBlock>
                </Label>
                <DockPanel Grid.Column="4">
                    <ComboBox x:Name="cboStartYear" SelectedValue="{Binding StartYear}"
                              IsEnabled="{Binding IsEnabled, ElementName=btnGetReport}" />
                    <ComboBox x:Name="cboStartMonth" DisplayMemberPath="Value" SelectedValuePath="Key"  SelectedValue="{Binding StartMonth}"
                              IsEnabled="{Binding IsEnabled, ElementName=btnGetReport}" />
                </DockPanel>

                <Label Grid.Row="1" Content="Organization Unit" />
                <ComboBox x:Name="cboOrganisationUnit" Grid.Row="1" Grid.Column="1" SelectedValue="{Binding OrganizationUnit}"
                          IsEnabled="{Binding IsEnabled, ElementName=btnGetReport}" />
                <Label Grid.Row="1" Grid.Column="3">
                    <TextBlock>
                        End Date <Italic FontSize="10">(yyyy, mm)</Italic>
                    </TextBlock>
                </Label>
                <DockPanel Grid.Row="1" Grid.Column="4">
                    <ComboBox x:Name="cboEndYear" SelectedValue="{Binding EndYear}" IsEnabled="{Binding IsEnabled, ElementName=btnGetReport}" />
                    <ComboBox x:Name="cboEndMonth" DisplayMemberPath="Value" SelectedValuePath="Key"  SelectedValue="{Binding EndMonth}"
                              IsEnabled="{Binding IsEnabled, ElementName=btnGetReport}"/>
                </DockPanel>

            </Grid>
            <DataGrid x:Name="dataGrid" Grid.Row="2" Margin="0,5,0,10" AutoGenerateColumns="False" 
                      CanUserDeleteRows="False" CanUserAddRows="False" ItemsSource="{Binding DatasetComparerIndicatorValues}"
                       AlternationCount="2" AlternatingRowBackground="WhiteSmoke">
                <DataGrid.Columns>
                    <DataGridTemplateColumn Header="Report Indicators Descriptions">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <Label Content="{Binding IndicatorDescription}" />
                                    <Label Margin="0">
                                        <TextBlock FontStyle="Italic" Foreground="Gray" FontSize="12" Text="{Binding DataElementDescription}" />
                                    </Label>
                                </StackPanel>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTextColumn Header="IQSMS" Binding="{Binding IQSMSValue}" />
                    <DataGridTextColumn Header="DHIS" Binding="{Binding DHISValue}" />
                </DataGrid.Columns>
            </DataGrid>

            <DockPanel Grid.Row="3" LastChildFill="False">
                <DockPanel.Resources>
                    <Style TargetType="{x:Type Button}">
                        <Setter Property="Padding" Value="10,2" />
                        <Setter Property="Margin" Value="10,0,0,0" />
                    </Style>
                </DockPanel.Resources>
                <Button x:Name="btnGetReport" IsDefault="True" DockPanel.Dock="Right" Click="btnGetReport_Click">Get Reports</Button>
                <Button x:Name="btnExportToExcel" DockPanel.Dock="Right" Click="btnExportToExcel_Click">Export to Excel</Button>
                <Button x:Name="btnCancel" DockPanel.Dock="Right" IsCancel="True" IsEnabled="False">Cancel</Button>
            </DockPanel>
        </Grid>
    </Grid>
</Window>
